<?php
$orderId = Order::model()->getOrderId();
$oOrderGoods = OrderGoods::model()->findByAttributes(array(
                                                          'order_id' => $orderId,
                                                          'goods_id' => $oRow->id
                                                     ));

$aOrderGoodsProperties = array();
if($oOrderGoods)
	$aOrderGoodsProperties = $oOrderGoods->getProperties();

?>

<div class="goods view" itemscope itemtype="http://schema.org/Product">
	<div class="wrapper">
		<div class="right-col">

			<ul>
				<li class="price">
					<div class="cart" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
						<?php if($oRow->old_price > 0): ?>
							<div class="off"><span>Скидка</span> <span><?php echo 100 - round($oRow->price / $oRow->old_price * 100); ?>% !</span></div>
							<div class="was"><?php echo Currencies::convert($oRow->old_price); ?></div>
						<?php endif; ?>
						<p class="price" itemprop="price"><?php echo Currencies::convert($oRow->price); ?><meta itemprop="priceCurrency" content="UAH"></p>
						<link itemprop="availability" href="http://schema.org/<?php echo $oRow->status == 1 ? 'InStock' : 'OutOfStock'; ?>">
						<input type="number" name="quantity" value="1" />
					</div>
				</li>

				<?php if(isset($aColors)): $oColor = null; ?>
					<li class="color">
						<label for="select-color"><?php echo _('Цвет'); ?>:</label>
						<select id="select-color" class="select cart-input" name="color">
							<?php foreach($aColors as $aVal): if(!empty($aVal['property'][4])): if($aVal['id'] == $oRow->id) $oColor = $aVal['property'][4][0]; ?>
								<option value="<?php echo $aVal['id'] ?>" <?php echo $aVal['id'] == $oRow->id ? ' selected' : ''; ?>><?php echo $aVal['property'][4][0]['value'] ?></option>
							<?php endif; endforeach; ?>
						</select>
						<?php if($oColor): ?><meta itemprop="color" content="<?php echo $oColor['value']; ?>" /><?php endif; ?>
					</li>
				<?php endif; ?>

				<?php if(isset($aSizes)): ?>
					<li class="sizes">
						<label for="select-size"><?php echo _('Размер'); ?> <?php if(!empty($oPageSize)): ?><sup><a class="fancy-text external" href="<?php echo $this->createUrl('/pages/default/index', array('id' => $oPageSize->createUrlId())); ?>?" target="_blank"><?php echo _('таблица размеров'); ?></a></sup><?php endif; ?></label>
						<select id="select-size" class="select cart-input" name="size">
							<option value=""><?php echo _('Выберите размер'); ?></option>
							<?php foreach($aSizes as $aVal): ?>
								<option <?php echo isset($aOrderGoodsProperties['size']) && $aOrderGoodsProperties['size'] == $aVal['id'] ? ' selected=""' : '' ?> value="<?php echo $aVal['id'] ?>" rel="<?php echo $aVal['stock_value_id'] ?>"><?php echo $aVal['value'] ?></option>
							<?php endforeach; ?>
						</select>
						<span>&nbsp;</span>
					</li>
				<?php endif; ?>

				<li class="btn-wrapper">
					<?php echo $this->widget('ext.fields.BtnBuy', array('oRow' => $oRow)); ?>
				</li>

				<li class="shipment">
					<a href="<?php echo $this->createUrl('/pages/default/index', array('id' => 'dostavka-i-oplata-tovarov')); ?>">
						<span>Бесплатная</span>
						<span>доставка</span>
					</a>
				</li>

				<li class="admin">
					<a href="<?php echo $this->createUrl('/admin/goods/editor/', array('id' => $oRow->id)); ?>">Редактировать</a>
				</li>
			</ul>
		</div>

		<div class="left-col">
			<h1 class="title" itemprop="name"><?php echo $oRow->title; ?></h1>
			<div class="sku" itemprop="sku" content="<?php echo $oRow->code; ?>"><?php echo $oRow->code; ?></div>

			<div class="gallery">
				<?php $pi = 0; if(!empty($oRow['photos'])) foreach($oRow['photos'] as $oPhoto): $pi++;
					if($oPhoto->is_main)
					{
						?>
						<a class="fancy main zoom" href="<?php echo $this->widget('ext.Img', array('oRow' => $oPhoto)); ?>">
						    <span style="overflow: hidden; max-height: 480px; max-width: 620px;">
							    <img alt="<?php echo $oRow['title']; ?>" itemprop="image" title="<?php echo $oRow['title']; ?>" src="<?php echo $this->widget('ext.Img', array('oRow' => $oPhoto, 'addSize' => false)); ?>" />
						    </span>
						</a>
						<?php
						break;
					}
				endforeach;
				?>
				<div class="clear"></div>

				<?php if(!empty($oRow['photos']) && count($oRow['photos']) > 1 || !empty($oRow['videos'])): ?>
					<div class="preview">
						<?php foreach($oRow['photos'] as $oPhoto): $pi++; ?>
							<a class="item<?php echo $pi == 2 ? ' selected' : ''; ?>" href="<?php echo $this->widget('ext.Img', array('oRow' => $oPhoto)); ?>"><span><img width="60" height="45" alt="<?php echo $oRow['title']; ?>" title="<?php echo $oRow['title']; ?>" src="<?php
									echo $this->widget('ext.Img', array(
									                                   'oRow' => $oPhoto,
									                                   'size' => ($pi == 1 ? '' : 'preview')
									                              ));
									?>" /></span></a>
						<?php endforeach; ?>

						<?php if(!empty($oRow['videos'])) foreach($oRow['videos'] as $oVideo): $pi++; ?>
							<a class="item video" href=""><span></span><span class="video-wrapper"><?php echo $oVideo->code; ?></span></a>
						<?php endforeach; ?>
					</div>
					<div class="clear"></div>
				<?php endif; ?>
			</div>

			<div class="clear"></div>

			<div class="desc">
				<h2>Информация о товаре</h2> <a id="review-link" class="review" href="#review">Отзывы</a>
				<div class="clear"></div>
				<div class="description" itemprop="description">
				<?php echo String::stripTagsAttributes(
					$oRow->description,
					'<p><h2><dt><dd><dl><img><ul><li><ol><a><iframe><object><param><embed>',
					array('href', 'src', 'alt', 'title', 'width', 'height'));
				?>
				</div>
				<div class="clear"></div>
			</div>

			<?php echo $this->widget('ext.CommentsWidget', array('oRow' => $oRow)); ?>

		</div>

		<div class="clear"></div>
	</div>

	<div class="clear"></div>


    <?php /* <div class="original-url">
        <a href="<?php echo $oRow->original_url; ?>">Original URL</a><br />
        <a href="<?php echo $this->createUrl('/admin/goods/editor/', array('id' => $oRow->id)); ?>">Редактировать</a><br />
        <a onclick="return confirm('Удалить товар?');" href="<?php echo $this->createUrl('/admin/goods/delete/', array('id' => $oRow->id)); ?>">Удалить</a>
    </div> */ ?>



	<?php if(!empty($oRelated)): ?>
	<div class="related">
		<div class="title"><?php echo _('Люди которые смотрели этот товар, смотрели также'); ?></div>

		<?php foreach($oRelated as $oRow): ?>
		<section>
			<?php if($oRow->getPhoto()): ?>
				<a href="<?php echo $this->createUrl('/goods/default/view', array('category' => $oRow->category_alias, 'id' => $oRow->alias)); ?>"><img class="lazy" alt="<?php echo $oRow->title; ?>" title="<?php echo $oRow->title; ?>" data-original="<?php echo $this->widget('ext.Img', array(
				                                                                              'oRow' => $oRow->getPhoto(),
				                                                                              'size' => 'list'
				                                                                         )); ?>" src="" /></a>
			<?php endif; ?>
			<a href="<?php echo $this->createUrl('/goods/default/view', array('category' => $oRow->category_alias, 'id' => $oRow->alias)); ?>"><?php echo $oRow->title; ?></a>
		</section>
		<?php endforeach; ?>
	</div>
	<?php endif; ?>

</div>

<script defer src="/js/jquery/fancybox/jquery.fancybox.pack.js"></script>
<script defer src="/js/jquery/zoom-master/jquery.zoom-min.js"></script>